<?php

require_once './include/common.inc.php';
require_once './include/cart.class_p.php';
require_once 'left.php';
require_once 'right.php';

$page_title = 'Acuity World WebShop';
$menu_id = 8;
$menu_str = PrintMenu();

$alert_message = '';
if ($act == "" && isPromoterLogin()) {	
    header("Location: promoter_summary.php");
    exit;
}

$act = $_POST['act'];
if ($act == "login") {
    $promoter_uid = $_POST['pid'];
    $password = $_POST['password']; 
    
    if(!empty($promoter_uid) && !empty($password)){
		$rs = $db->get_one("SELECT * FROM `promoter_info` WHERE `id`='" . $promoter_uid . "' and status=1");
		
		if($rs && md5($password) == $rs['password1']){
			
			//clear all cookies  and session first
			if(isUserLogin())
			{
				Cookie('webshopuser','',0);
			} 
            Cookie("webshoppromoter",base64_encode($rs['id']."\t".$rs['email']."\t".$rs['faq1']."\t".$timestamp),null);
			session_start();
			$cart = new cart();
			$cms = getCms($rs['id']);
			$promoter_cmsosd=$cms['cms_osd'];
			$cart->setPromoterOsd($promoter_cmsosd);
			
            header("Location: promoter_summary.php");
            exit;
        } else {
            $alert_message = "Invalid Promoter's ID or Password! Please try again.";
        }
    } else {
        $alert_message = "Please enter your Promoter's ID and Password to login.";
    }
}


require_once PrintEot('header');
require_once PrintEot('left');
require_once PrintEot('promoter_login');
require_once PrintEot('right');
require_once PrintEot('footer');

?>